<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();



//用户检测
$MB->Open('','login');


switch ($mudi){
	case 'moreDel':
		$menuFileID = 504;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		MoreDel();
		break;

	case 'dayDel':
		$menuFileID = 504;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		DayDel();
		break;

	default:
		die('err');
}

$MB->Close();
$DB->Close();





// 批量删除
function MoreDel(){
	global $DB,$mudi,$menuFileID,$menuTreeID;

	$dataType	= OT::PostStr('dataType');
	$dataTypeCN	= OT::PostStr('dataTypeCN');
	$backURL	= OT::PostStr('backURL');
	$selDataID	= OT::Post('selDataID');

	$selCount = OT::NewCount($selDataID);
	if ($selCount <= 0){
		JS::AlertBackEnd('请先选择要删除的记录.');
	}

	$whereStr = '';
	for ($i=0; $i<$selCount; $i++){
		$whereStr .= ','. intval($selDataID[$i]);
	}
	if ($whereStr == ''){
		JS::AlertBackEnd('请先选择要删除的记录.');
	}

	$judRes = $DB->query('delete from '. OT_dbPref .'autoRunLog where ARL_ID in (0'. $whereStr .')');
		if ($judRes){
			$alertRes='成功';
		}else{
			$alertRes='失败';
		}

	Adm::AddLog(array(
		'note'	=> '【'. $dataTypeCN .'】批量删除'. $alertRes .'！',
		));

	JS::AlertHrefEnd('批量删除'. $alertRes .'.',$backURL);
}



// 按天数删除
function DayDel(){
	global $DB;

	$backURL= OT::GetStr('backURL');
	$day	= OT::GetInt('day');

	if ($day < 1){
		JS::AlertBackEnd('天数指定错误.');
	}

	$typeSql = '';
	if ($day < 30){ $typeSql = ',"day"'; }

	$day = $day*(-1);

	$DB->query('delete from '. OT_dbPref .'autoRunLog where ARL_type not in ("dayStati"'. $typeSql .') and ARL_time<'. $DB->ForTime(TimeDate::Add('d',$day,TimeDate::Get())));

	JS::AlertHref('删除成功.',$backURL);

}
?>